package com.example.jcservice.controller;

import com.example.jcservice.service.YktService;
import com.example.jcservice.stType.Resive.Ykt.YktRecords;
import com.example.jcservice.stType.Resive.Ykt.YktUserInfo;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.io.UnsupportedEncodingException;
import java.util.HashMap;
import java.util.Map;


@RestController
public class YktController {
    @Resource
    private YktService service;

    /**
     * 测试接口
     * */
    @GetMapping("/ykttest")
    public Map<String, Object> sayHello() {
        Map<String, Object> result = new HashMap<>();
        result.put("message", "显示这句话，说明YktLoginController正常运行");
        return result;
    }

    /**
     * 一卡通登录接口，获取个人账户基本信息
     *
     * @return*/
    @GetMapping("/yktlogin")
    public YktUserInfo demo(@RequestParam("username") String username, @RequestParam("password") String password) throws UnsupportedEncodingException {
        System.out.println("传入参数 学号：" + username);
        System.out.println("传入参数 密码：" + password);

        YktUserInfo result = service.login(username, password);

        return result;
    }

    /**
     * 获取消费记录接口
     * */
    @GetMapping("/yktrecords")
    public YktRecords demo(@RequestParam("username") String username, @RequestParam("password") String password, @RequestParam("start") String start, @RequestParam("end") String end) throws UnsupportedEncodingException {
        System.out.println("传入参数 学号：" + username);
        System.out.println("传入参数 密码：" + password);
        System.out.println("传入参数 起始日期：" + start);
        System.out.println("传入参数 结束日期：" + end);

        YktRecords result = service.getRecords(username,password,start,end);

        return result;
    }

    /**
     * 挂失接口
     *
     * @return*/
    @GetMapping("/yktgs")
    public String yktGs(@RequestParam("username") String username, @RequestParam("password") String password , @RequestParam("state") String state){
        String result = service.YktGs(username,password,state);

        return result;
    }

    /**
     * 设置单日消费限额接口
     *
     * @return*/
    @GetMapping("/yktlimit")
    public String setLimit(@RequestParam("username") String username, @RequestParam("password") String password , @RequestParam("money") String money){
        String result = service.YktLimit(username,password,money);

        return result;
    }

}
